package com.lnu_devteam.zongce.model.enums;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xbaozi
 * @description 用户角色枚举类
 * @date 2023/3/23 19:50
 **/
public enum RoleEnum {
    USER("user", 0),
    ADMIN("admin", 1),
    SUPER("super", 2);

    private final String role;
    private final Integer auth;

    RoleEnum(String role, Integer auth) {

        this.role = role;
        this.auth = auth;
    }

    public static RoleEnum getRollByAuth(Integer auth) {
        List<RoleEnum> rollList = Arrays.stream(values())
                .filter(item -> item.auth.equals(auth))
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(rollList)) {
            return null;
        }
        return rollList.get(0);
    }


    public String getRole() {
        return role;
    }

    public Integer getAuth() {
        return auth;
    }
}